<template>
	<view class="goodsBox  bgcf pb20">
		<view class="pr" @click="clickDetail()">
			<view class="pa" style="top: 10rpx; left: 10rpx;">
				
			</view>
			<image style="width: 330rpx;height: 330rpx;"
				:src="item.platformGoodsSpecMix&&item.platformGoodsSpecMix[0].image?item.platformGoodsSpecMix&&item.platformGoodsSpecMix[0].image.split(',')[0]:''" mode="aspectFill">
			</image>
			<!-- <u-lazy-load threshold="-450" :image="item.image" :index="index"></u-lazy-load> -->
			<view class="fs26 c3 fwb p010 u-line-2" style="width: 330rpx;">
				{{item.customGoodsName}}
			</view>
			<view class="fs22 c9 fw4 mt10 p010 textOver" style="width: 330rpx;">
				{{item.introduce||''}}
			</view>
		</view>
		<view class="goodsLabel m010 u-text-left" style="margin-top: 10rpx;">
			{{item.platformGoodsSpecMix&&item.platformGoodsSpecMix[0].specName}}
		</view>
		<view  class="df aic cEF2929  fwb p010" v-if="TOKEN&&item.referencePriceRange && item.referencePriceRange!='0.00' &&$common.calcTime(item.startTime,item.endTime)">
			<text class="fs24">单价:</text> <text
				class="fs26">{{item.referencePriceRange}}</text>
		</view>
		<view class="df aic jcsb p010 mt10">
			
			<view class="">
				<view class="df aic" style="color: #EF2929;" v-if="TOKEN">
					<Vip class="mr5" v-if="item.priceRangeOne&&TOKEN&&((item.platformGoodsSpecMix.length==1&&!item.platformGoodsSpecMix[0].purNum>0))&&$common.calcTime(item.startTime,item.endTime)"></Vip>
					<text class="fs22">￥</text>
					<!-- <text v-if="$common.calcTime(item.startTime,item.endTime) |">{{item.priceRange}}</text> -->
					<text class="fs28 fw5">{{$common.calcTime(item.startTime,item.endTime)?item.priceRange||0:'待报价'}}</text>
					<!-- ||item.source -->
					<!-- <text class="fs22 c3">/{{item.priceRange||0}}</text> -->
					<!-- <text class="fs22 c9">/{{item.platformGoodsSpecMix&&item.platformGoodsSpecMix[0].saleUnit}}</text> -->
				</view>

				<view class="df aic fs26 fwb" style="color: #EF2929;" v-else>
					登录可见价格
				</view>
				<!-- <text class="tdlt c9 fs22">￥35.9</text> -->
			</view>
			<!-- <view class="cf expediting df aic">
					<nmr-icon name="shijian-4" size="28" color="#fff"></nmr-icon>
					<text class="fs22 fw5">催货</text>
				</view> -->
			<nmr-icon v-if="!TOKEN &&  $common.calcTime(item.startTime,item.endTime,true) " @click.stop="handleLogin"
				name="jiatianjia-yuankuang" size="40" color="#47A848"></nmr-icon>
			<view class="pr" v-else>
				<u-badge v-if="item.platformGoodsSpecMix.length!=1" :offset="[-13,-12]" size="mini" :count="allNum"
					type="error">
				</u-badge>
				<view class="" v-if="$common.calcTime(item.startTime,item.endTime)">
				
					<zm-number-box 
					:saleUnit="item.platformGoodsSpecMix[0].saleUnit"
					 :startSaleNum="item.platformGoodsSpecMix[0].startSaleNum" :step="item.platformGoodsSpecMix[0].startSaleNum&&item.platformGoodsSpecMix[0].isDouble==1?item.platformGoodsSpecMix[0].startSaleNum:1" :disabledInput="item.platformGoodsSpecMix[0].isDouble==1"  size="40"
					 v-if="item.platformGoodsSpecMix.length==1"
						@change.stop="valChange($event,item,index)" :min="0"
						v-model="item.platformGoodsSpecMix[0].purNum" v-else></zm-number-box>
					<!-- <nmr-icon v-else @tap.stop="chooseSkuShow(item)" name="jiatianjia-yuankuang" size="40"
						color="#47A848"></nmr-icon> -->
						<view class="fs22 df aic jcc spce-box"  v-else @tap.stop="chooseSkuShow(item)">
							选规格
						</view>
				</view>
				<!-- 多规格的情况下 需要选择规格 -->

			</view>
		</view>
		<view class="text-under c9 fs24 ml10" v-if="item.priceRangeOne&&TOKEN&&$common.calcTime(item.startTime,item.endTime)">原价:￥{{item.priceRangeOne}}</view>
	</view>

</template>

<script>
import Decimal from 'decimal.js'
	export default {
		props: ['item', 'type', 'index', "goodsCarList"],
		data() {
			return {}
		},
		watch: {
			// list: {
			// 	handler(e) {
			// 		e.forEach(item =>{
			// 			item.numAll = 0
			// 			item.platformGoodsSpecMix.forEach(i => {
			// 				item.numAll += i.purNum
			// 			})
			// 		})
			// 	},
			// 	immediate: true,
			// 	deep: true
			// }
		},
		computed: {
			allNum() {
				let numAll = new Decimal(0)
				this.item.platformGoodsSpecMix.forEach(i => {
					numAll =  new Decimal(i.purNum).add(numAll)
				})
				return numAll
			},

		},
		methods: {

			clickDetail() {
				uni.navigateTo({
					url: '/pages/goods/detail?id=' + this.item.platformGoodsId
				})
			},
			valChange(e, item, index) {
				this.$set(this.item.platformGoodsSpecMix[0], 'purNum', e)
				this.handleCart(this.item.platformGoodsSpecMix[0], index)
				console.log(this.item.platformGoodsSpecMix[0].purNum)
			},
			handleCart(e) {
				let goodsCarList = this.goodsCarList || []
				let index = goodsCarList.findIndex(i => i.platformGoodsSpecMixId == e.platformGoodsSpecMixId)
				if (index == -1) { //购物车中没有这个商品  新增操作
					goodsCarList.unshift(e)
				} else { //购物车中有这个商品  修改操作
					if (e.purNum == 0) { //删除操作
						goodsCarList.splice(index, 1)
					} else {
						//只有購物車的時候 才手動更新列表
						goodsCarList[index].purNum = e.purNum
						goodsCarList[index].busType = ''
						goodsCarList[index].platformPrice = e.platformPrice
					}
				}
				this.$emit('changeCarList', goodsCarList)
				this.$emit('changeGoods', this.item)
			},
			handleLogin() {
				this.$emit('handleLogin')
			},
			chooseSkuShow(item) {
				this.$emit('chooseSkuShow', item)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.goodsBox {
		margin: 20rpx 0 0 20rpx;
		border-radius: 20rpx;
		width: 330rpx;

		image {
			border-radius: 20rpx 20rpx 0 0;
		}
	}

	.tdlt {
		text-decoration: line-through
	}

	.expediting {
		padding: 2rpx 15rpx;
		background: linear-gradient(90deg, #48A147 0%, #8AE38A 100%);
		border-radius: 22rpx;
	}
	.cEF2929{
		color: #EF2929;
	}
	.spce-box{
		color: white;
		padding: 2rpx 10rpx;
		background: #48A147;
		border-radius: 22rpx;
	}
</style>